package com.itheima.controller;


import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.pojo.StudentResult;
import com.itheima.service.impl.StudentServiceImpl;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    //4.1 学员列表查询
    @GetMapping
    public Result getPage(StudentQueryParam queryParam){
        log.info("分页查询，参数：{}",queryParam);
        return Result.success(studentService.pageStu(queryParam));
    }

    //4.2 删除学员
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        log.info("删除学员，id列表：{}",ids);
        studentService.removeByIds(ids);
        return Result.success();
    }

    //4.3 添加学员
    @PostMapping
    public Result insertStudent(@RequestBody Student student){
        log.info("添加学员，参数：{}",student);
        studentService.save(student);
        return Result.success();
    }

    //4.4 根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据id查询学员，id：{}",id);
        return Result.success(studentService.getById(id));
    }

    //4.5 修改学员
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        log.info("修改学员，参数：{}",student);
        studentService.updateById(student);
        return Result.success();
    }

    //4.6 违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Integer score){
        log.info("违纪处理，id：{}，score：{}",id,score);

        return Result.success();
    }










  /*  //4.1 学员列表查询
    @GetMapping
    public Result getPage(StudentQueryParam queryParam){
        log.info("分页查询，参数：{}",queryParam);
        StudentResult studentResult = studentService.getPage(queryParam);
        return Result.success(studentResult);
    }

    //4.2 删除学员
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        log.info("删除学员，id列表：{}",ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    //4.3 添加学员
    @PostMapping
    public Result insertStudent(@RequestBody Student student){
        log.info("添加学员，参数：{}",student);
        studentService.insertStudent(student);
        return Result.success();
    }

    //4.4 根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据id查询学员，id：{}",id);
        Student student = studentService.getById(id);
        return Result.success(student);
    }

    //4.5 修改学员
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        log.info("修改学员，参数：{}",student);
        studentService.update(student);
        return Result.success();
    }

    //4.6 违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Integer score){
        log.info("违纪处理，id：{}，score：{}",id,score);
        studentService.updateViolation(id,score);
        return Result.success();
    }
*/
}
